<template>
	<view class="content">
		<view class="top">
			<view class="imgCon">
				<img style="width: 100%;height: 100%;" :src="pic" alt="暂无">
			</view>
			<view class="textCon">
				<view class="textTop">{{name}}</view>
				<view class="textMid">{{group}}</view>
				<view class="textBtm">{{shList}}</view>
			</view>

		</view>
		<view class="mid"></view>
		<view class="btm">
			<view class="gnzj" @click='toLogin()'>
				<view class="iconL"><uni-icons type="staff" size="30" color="#e08020"></uni-icons></view>
				<view class="text">登录/切换用户</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>

			<view class="gnzj" @click='getUserGroup()'>
				<view class="iconL"><uni-icons type="reload" size="30" color="#e08020"></uni-icons></view>
				<view class="text">重新获取用户组</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>

			<view class="gnzj" @click="toAddSpPic" v-if="this.group === '管理组'">
				<view class="iconL"><uni-icons type="images" size="30" color="#e08020"></uni-icons></view>
				<uni-badge class="szjb" :text="this.spPicNum"/>
				<view class="text">上传商品照片</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>

			<view class="gnzj" @click="toAddSpPrice" v-if="this.group === '管理组'">
				<view class="iconL"><uni-icons type="wallet" size="30" color="#e08020"></uni-icons></view>
				<uni-badge class="szjb" :text="this.spPriceNum"/>
				<view class="text">添加商品价格</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>

<!-- 			<view class="gnzj" @click="toAddNewSp" v-if="this.group === '管理组'" >
				<view class="iconL"><uni-icons type="image" size="30" color="#e08020"></uni-icons></view>
				<view class="text">上传新品照片</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view> -->
			
			<view class="gnzj" @click="toDataChart" v-if="this.group === '管理组' && this.name === 'kiki!'">
				<view class="iconL"><uni-icons type="map-filled" size="30" color="#e08020"></uni-icons></view>
				<view class="text">数据图表</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>

			<view class="gnzj" @click="toDataAdmin" v-if="this.group === '管理组'">
				<view class="iconL"><uni-icons type="gear-filled" size="30" color="#e08020"></uni-icons></view>
				<view class="text">数据管理</view>
				<view class="iconR"><uni-icons type="right" size="30" color="#e08020"></uni-icons></view>
			</view>
			
			<view class="gnzj">
				<view class="iconL"><uni-icons type="bars" size="30" color="#e08020"></uni-icons></view>
				<view class="text">当前版本:{{version}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '../../utils/config.js'
	export default {
		onLoad(){
			this.getNumberFromServer()
		},
		data() {
			return {
				name: uni.getStorageSync('userData')['name'],
				group: uni.getStorageSync('userData')['model'],
				shList: uni.getStorageSync('userData')['shList'],
				pic: config.staticSh + uni.getStorageSync('userData')['imgPic'],
				version: config.version,
				spPicNum: 0,
				spPriceNum: 0,
			}
		},
		methods: {
			// 获取需要输入数据量
			getNumberFromServer(){
				let that = this
				this.request({
					url: config.baseUrl + "/wx/getSpNotPicByName",
					data:{
						'nickname': '',
						'ddkh': '',
					}
				}).then(res => {
					that.spPicNum = res.data.length
				})
				this.request({
					url: config.baseUrl + "/wx/getTradeNoPrice",
				}).then(res => {
					that.spPriceNum = res.data.length
				})
			},
			// 跳转到登录界面
			toLogin() {
				uni.navigateTo({
					url: "./login/login",
				})
			},
			// 跳转到上传商品照片页面
			toAddSpPic() {
				uni.navigateTo({
					url: "./addSpPic/addSpPic",
				})
			},
			// 跳转到商品上传价格
			toAddSpPrice(){
				uni.navigateTo({
					url: "./addSpPrice/addSpPrice",
				})
			},
			// 跳转到新品
			toAddNewSp(){
				uni.navigateTo({
					url: "./addNewSp/addNewSp",
				})
			},
			// 跳转到数据管理
			toDataAdmin(){
				uni.navigateTo({
					url: "./dataAdmin/dataAdmin",
				})
			},
			// 跳转到数据图表
			toDataChart(){
				uni.navigateTo({
					url: "./dataChart/dataChart",
				})
			},
			// 重新获取用户数组
			getUserGroup() {
				this.getNumberFromServer()
				let userData = uni.getStorageSync('userData')
				this.request({
					url: config.baseUrl + "/wx/loginWx",
					data: {
						username: userData['username'],
						password: userData['password'],
					},
				}).then(res => {
					if (res.status === 200) {
						uni.setStorageSync('userData', res.data);
						uni.reLaunch({
							url: '/pages/mine/index'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #eee;
	}
	.szjb{
		left: -130rpx;
	}
	.top {
		height: 300rpx;
		width: 100%;
		background-color: #fff;

		.imgCon {
			height: 200rpx;
			width: 200rpx;
			padding: 50rpx;
			float: left;

			img {
				border-radius: 50rpx;
				border: 1rpx solid black;
				width: 100%;
				height: 100%;
			}
		}

		.textCon {
			width: 350rpx;
			height: 200rpx;
			float: left;
			padding: 50rpx;

			.textTop {
				margin: 20rpx;
				font-size: 50rpx;
			}

			.textMid {
				margin: 20rpx;
				color: #757575;
			}

			.textBtm {
				margin: 20rpx;
				mragin-top: 10rpx;
				color: #757575;
			}
		}
	}

	.mid {
		height: 50rpx;
	}

	.btm {
		width: 100%;
		height: 500rpx;

		.gnzj {
			width: 98%;
			margin-left: 1%;
			height: 100rpx;
			background-color: #fff;
			font-size: 40rpx;
			text-align: center;
			margin-top: 5rpx;
			float: left;

			.iconL {
				margin: 20rpx;
				float: left;
				display: inline-block;
			}

			.text {
				margin: 20rpx;
				float: left;
				display: inline-block;
			}

			.iconR {
				margin: 20rpx;
				float: right;
				display: inline-block;
			}
		}
	}
</style>